package smartcarpool.smartspaceservice;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

public class TripleList implements Parcelable {

	private List<Triple> tripleList;

	public TripleList() {
        tripleList = new ArrayList<Triple>();
	}

    public TripleList(Vector<Vector<String>> tripleVector){
        tripleList = new ArrayList<Triple>();
        for (Vector<String> triple : tripleVector){
            tripleList.add(new Triple(triple));
        }
    }

    private TripleList(Parcel parcel){
        tripleList = new ArrayList<Triple>();
        parcel.readTypedList(tripleList,Triple.CREATOR);
    }

	@Override
	public int describeContents() {
		return 0;
	}

	public static final Creator<TripleList> CREATOR
    = new Creator<TripleList>() {
		public TripleList createFromParcel(Parcel in) {
			return new TripleList(in);
		}

		public TripleList[] newArray(int size) {
			return new TripleList[size];
		}
	};

	@Override
	public void writeToParcel(Parcel parcel, int arg1) {
		parcel.writeTypedList(tripleList);
	}

    public Vector<Vector<String>> toVector(){
        Vector<Vector<String>> result = new Vector<Vector<String>>();
        for (Triple triple : tripleList) {
            result.add(triple.toVector());
        }
        return result;
    }

    public boolean add(Triple triple){
        return tripleList.add(triple);
    }
    public Triple get(int location){
        try {
            return tripleList.get(location);
        } catch (ArrayIndexOutOfBoundsException e){
            e.printStackTrace();
        }
        return null;
    }
    public int size(){
        return tripleList.size();
    }

}
